import java.util.Scanner;

/**
 * Created by forcht on 2018/4/24.
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            int l=s.length();
            s = s + s;
            int min =Integer.MAX_VALUE;
            int left = 0;
            int right = -1;
            int[] a = new int[5];
            while (left < l&&right<s.length()) {
                if (a[0] > 0 && a[1] > 0 && a[2] > 0 && a[3] > 0 && a[4] > 0) {
                    int t = right - left + 1;
                    min = t <min ? t : min;
                    if (s.charAt(left) >= 'A' && s.charAt(left) <= 'E') {
                        a[s.charAt(left) - 'A']--;
                    }
                    left++;
                } else {
                    right++;
                    if (right<s.length()&&s.charAt(right) >= 'A' && s.charAt(right) <= 'E') {
                        a[s.charAt(right) - 'A']++;
                    }
                }
            }
            System.out.println(l-min);
        }
    }
}
